package com.example.blog.config;

import com.example.blog.interceptor.LoginInterceptorSession;
import com.example.blog.interceptor.LoginInterceptorToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptorToken loginInterceptor;
    @Autowired
    private LoginInterceptorSession loginInterceptorSession;

    public void addInterceptors(InterceptorRegistry registry) {
        /**
         *  token 实现的拦截器
         */
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/js/**")
                //允许直接访问的接口
                .excludePathPatterns(
                        "/sysUser/login",
                        "/sysUser/register",
//                        "/article/page",
//                        "/article/detail",
//
//                        //TODO 开发暂时允许访问
//                        "/sysUser/list",
//                        "/sysUser/getById",
//                        "/sysUser/page",
//                        "/category/**",
//                        "/sysUser/save",
//                        "/sysRole/**",
//                        //放行全部
//                        "/**",

//                        "/article/**",
                        "/article/uPage",
                        "/article/uDetail",
                        "/views",

                        "/swagger-ui/**",
                        "/swagger-ui.html",
                        "/swagger-resources/**",
                        "/images/**",
                        "/webjars/**",
                        "/v2/api-docs",
                        "/configuration/ui",
                        "/configuration/security",
                        "/doc.html"
                );

//        /**
//         *  session 实现的 登录拦截器
//         */
//        registry.addInterceptor(loginInterceptor)
//                .addPathPatterns("/**");

    }
}
